//
//  StatusRetweetedCell.swift
//  新浪微博01
//
//  Created by 李国伟 on 15/12/13.
//  Copyright © 2015年 李国伟. All rights reserved.
//

import UIKit

class StatusRetweetedCell: StatusCell {

    //重写模型的didset方法
    override var  viewModel: StatusViewModel?{
        didSet{
            //设置转发评论
            retweetedLabel.text = viewModel?.retweetedText

            //根据配图的数量设置间距
           let offset = viewModel?.thumbnailUrls?.count > 0 ? StatusCellMargin : 0
            pictureView.snp_updateConstraints { (make) -> Void in
                make.top.equalTo(retweetedLabel.snp_bottom).offset(offset)
            }
        }
    }
    
    //懒加载控件
    private lazy var backbutton: UIButton = {
        let button = UIButton()
        button.backgroundColor = UIColor(white: 0.95, alpha: 1)
        return button
    }()
    
    private lazy var retweetedLabel = UILabel(title: "我是传奇，新浪微博我是传奇，新浪微博我是传奇，新浪微博我是传奇，新浪微博", fontsize: 14, screenInset: StatusCellMargin, color: UIColor.darkGrayColor())
}

//添加控件，设置约束
extension StatusRetweetedCell{
   
    override func setupUI() {
        super.setupUI()
        contentView.insertSubview(backbutton, belowSubview: pictureView)
        contentView.insertSubview(retweetedLabel, aboveSubview: backbutton)
        
        //设置backButoon的约束
        backbutton.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentLabel.snp_bottom)
            make.left.equalTo(contentView)
            make.right.equalTo(contentView)
            make.bottom.equalTo(bottomView.snp_top)
            
        }
        
        //设置转发label的约束
        retweetedLabel.snp_makeConstraints { (make) -> Void in
           make.top.equalTo(backbutton.snp_top).offset(StatusCellMargin)
            make.left.equalTo(backbutton.snp_left).offset(StatusCellMargin)
        }
        
        //设置配图视图
        pictureView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(retweetedLabel.snp_bottom).offset(StatusCellMargin)
            make.left.equalTo(retweetedLabel)
        }
    }
}